package com.shd.edanpei.presenter;


import com.shd.edanpei.base.BasePresenterImpl;
import com.shd.edanpei.base.network.api.ApiCreator;
import com.shd.edanpei.base.network.rx.BaseObserver;
import com.shd.edanpei.base.network.rx.RxTransformer;
import com.shd.edanpei.bean.QrcodeBean;
import com.shd.edanpei.db.DaoManager;
import com.shd.edanpei.presenter.contract.QrcodeContract;

import io.reactivex.android.schedulers.AndroidSchedulers;

/**
 * Created by mc on 2018/3/29.
 * yang-wen-wen
 */
public class QrcodePresenter extends BasePresenterImpl<QrcodeContract.QrcodeIView>
        implements QrcodeContract.QrcodeIPresenter {

    public QrcodePresenter(QrcodeContract.QrcodeIView mView) {
        super(mView);
    }

    @Override
    public void getQrcode() {
        mBaseIView.showLoading("");
        ApiCreator.getApi().getQrcode(DaoManager.getInstance().getUserBean().getId())
                .compose(RxTransformer.<QrcodeBean>errorHandle())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<QrcodeBean>() {
                    @Override
                    protected void onSuccess(QrcodeBean data) {
                        mBaseIView.setQrcode(data);
                    }

                    @Override
                    public void onFinish() {
                        mBaseIView.stopLoading();
                    }
                });
    }
}
